home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1995 November / EnigmA AMIGA RUN 02 (1995)(G.R. Edizioni)(IT)[!][issue 1995-11][Skylink CD].iso / earcd / program / misc / bgui12.lha / Classes / AreaClass / AreaClass.c next >
C/C++ Source or Header  |  1995-06-09  |  5KB  |  252 lines

  1. /*
  2. **           File: areaclass.c
  3. **    Description: BOOPSI (BGUI) area gadget class.
  4. **      Copyright: (C) Copyright 1994-1995 Jaba Development.
  5. **             (C) Copyright 1994-1995 Jan van den Baard.
  6. **             All Rights Reserved.
  7. **/
  8.  
  9. #include <exec/types.h>
  10. #include <intuition/intuition.h>
  11. #include <libraries/bgui.h>
  12.  
  13. #include <clib/alib_protos.h>
  14.  
  15. #include <proto/exec.h>
  16. #include <proto/intuition.h>
  17. #include <proto/bgui.h>
  18. #include <proto/utility.h>
  19.  
  20. #include <string.h>
  21. #include <stdlib.h>
  22.  
  23. #include "areaclass.h"
  24.  
  25. /*
  26. **    Compiler stuff.
  27. **/
  28. #ifdef _DCC
  29. #define SAVEDS __geta4
  30. #define ASM
  31. #define REG(x) __ ## x
  32. #else
  33. #define SAVEDS __saveds
  34. #define ASM __asm
  35. #define REG(x) register __ ## x
  36. #endif
  37.  
  38. /*
  39. **    AreaClass object instance data.
  40. **/
  41. typedef struct {
  42.     UWORD        MinWidth;    /* Minimum width of area.  */
  43.     UWORD        MinHeight;    /* Minimum height of area. */
  44.     struct IBox    AreaBox;    /* Current area bounds.    */
  45. } AOD;
  46.  
  47. /*
  48. **    Some cast macros.
  49. */
  50. #define OPSET(x)    ((struct opSet *)x)
  51. #define OPGET(x)    ((struct opGet *)x)
  52. #define GPRENDER(x)    ((struct gpRender *)x)
  53. #define GADGET(x)    ((struct Gadget *)x)
  54. #define GDIM(x)         ((struct grmDimensions *)x)
  55.  
  56. /*
  57. **    Send a notification method.
  58. **/
  59. ULONG Notify( Object *obj, struct GadgetInfo *gi, ULONG flags, Tag tag1, ... )
  60. {
  61.     return( DoMethod( obj, OM_NOTIFY, ( struct TagItem * )&tag1, gi, flags ));
  62. }
  63.  
  64. /*
  65. **    Class dispatcher.
  66. **
  67. **    SAS Users: You should either compile this module with
  68. **           stack checking turned off (NOSTACKCHECK) or
  69. **           you must use the "__interrupt" qualifier in
  70. **           this routine.
  71. **/
  72. SAVEDS ASM ULONG AreaDispatch( REG(a0) Class *cl, REG(a2) Object *obj, REG(a1) Msg msg )
  73. {
  74.     AOD            *data;
  75.     struct TagItem        *tag, *tstate;
  76.     ULONG             rc = 0L;
  77.  
  78.     switch ( msg->MethodID ) {
  79.  
  80.         case    OM_NEW:
  81.             /*
  82.             **    Let the superclass create the object.
  83.             **/
  84.             if ( rc = DoSuperMethodA( cl, obj, msg )) {
  85.                 /*
  86.                 **    Get instance data.
  87.                 **/
  88.                 data = ( AOD * )INST_DATA( cl, rc );
  89.                 /*
  90.                 **    Clear data (dunno if the system
  91.                 **    does this ????)
  92.                 **/
  93.                 bzero(( char * )data, sizeof( AOD ));
  94.                 /*
  95.                 **    Read attributes.
  96.                 **/
  97.                 tstate = OPSET( msg )->ops_AttrList;
  98.                 while ( tag = NextTagItem( &tstate )) {
  99.                     switch ( tag->ti_Tag ) {
  100.                         case    AREA_MinWidth:
  101.                             data->MinWidth = tag->ti_Data;
  102.                             break;
  103.                         case    AREA_MinHeight:
  104.                             data->MinHeight = tag->ti_Data;
  105.                             break;
  106.                     }
  107.                 }
  108.                 /*
  109.                 **    Minimal width and height required!
  110.                 **/
  111.                 if ( data->MinWidth && data->MinHeight )
  112.                     return( rc );
  113.                 /*
  114.                 **    Fail :(
  115.                 **/
  116.                 CoerceMethod( cl, ( Object * )rc, OM_DISPOSE );
  117.                 rc = 0L;
  118.             }
  119.             break;
  120.  
  121.         case    OM_GET:
  122.             /*
  123.             **    Do we know the requested
  124.             **    attribute?
  125.             **/
  126.             if( OPGET( msg )->opg_AttrID == AREA_AreaBox ) {
  127.                 /*
  128.                 **    Simply return a pointer to the
  129.                 **    area which is computed at rendering
  130.                 **    time.
  131.                 **/
  132.                 data = ( AOD * )INST_DATA( cl, obj );
  133.                 *( OPGET( msg )->opg_Storage ) = ( ULONG )&data->AreaBox;
  134.                 rc = 1L;
  135.             } else
  136.                 rc = DoSuperMethodA( cl, obj, msg );
  137.             break;
  138.  
  139.         case    GM_RENDER:
  140.  
  141.             struct IBox    *hitbox;
  142.             Object        *frame = NULL;
  143.             ULONG         fwidth, fheight;
  144.  
  145.             /*
  146.             **    See if rendering is allowed.
  147.             **/
  148.             if ( rc = DoSuperMethodA( cl, obj, msg )) {
  149.                 /*
  150.                 **    Get instance data.
  151.                 **/
  152.                 data = ( AOD * )INST_DATA( cl, obj );
  153.                 /*
  154.                 **    Obtain the hitbox position and
  155.                 **    size of the object.
  156.                 **/
  157.                 DoSuperMethod( cl, obj, OM_GET, BT_HitBox, &hitbox );
  158.                 /*
  159.                 **    Copy this data to our private
  160.                 **    buffer.
  161.                 **/
  162.                 *( &data->AreaBox ) = *hitbox;
  163.                 /*
  164.                 **    Do we have a frame?
  165.                 **/
  166.                 DoSuperMethod( cl, obj, OM_GET, BT_FrameObject, &frame );
  167.                 if ( frame ) {
  168.                     /*
  169.                     **    Get frame width and height and
  170.                     **    adjust accoordingly.
  171.                     **/
  172.                     DoMethod( frame, OM_GET, FRM_FrameWidth,  &fwidth );
  173.                     DoMethod( frame, OM_GET, FRM_FrameHeight, &fheight );
  174.  
  175.                     data->AreaBox.Left   += fwidth;
  176.                     data->AreaBox.Top    += fheight;
  177.                     data->AreaBox.Width  -= fwidth    << 1;
  178.                     data->AreaBox.Height -= fheight << 1;
  179.                     /*
  180.                     **    Notify the main program.
  181.                     **/
  182.                     Notify( obj, GPRENDER( msg )->gpr_GInfo, 0L, GA_ID, GADGET( obj )->GadgetID, TAG_END );
  183.                 }
  184.             }
  185.             break;
  186.  
  187.         case    GRM_DIMENSIONS:
  188.             /*
  189.             **    First the superclass.
  190.             **/
  191.             DoSuperMethodA( cl, obj, msg );
  192.             /*
  193.             **    We simply add the specified minimum
  194.             **    width and height which are passed
  195.             **    to us at create time.
  196.             **/
  197.             data = ( AOD * )INST_DATA( cl, obj );
  198.             *( GDIM( msg )->grmd_MinSize.Width  ) += data->MinWidth;
  199.             *( GDIM( msg )->grmd_MinSize.Height ) += data->MinHeight;
  200.             rc = 1L;
  201.             break;
  202.  
  203.         case    GM_HITTEST:
  204.             /*
  205.             **    I intercept this method here to prevent
  206.             **    gadget clicks from being reported.
  207.             **/
  208.             break;
  209.  
  210.         default:
  211.             /*
  212.             **    All the rest goes to the
  213.             **    superclass.
  214.             **/
  215.             rc = DoSuperMethodA( cl, obj, msg );
  216.             break;
  217.     }
  218.     return( rc );
  219. }
  220.  
  221. /*
  222. **    Initialize the class.
  223. **/
  224. Class *InitAreaClass( void )
  225. {
  226.     Class            *super, *cl = NULL;
  227.  
  228.     /*
  229.     **    Obtain the BaseClass pointer which
  230.     **    will be our superclass.
  231.     **/
  232.     if ( super = BGUI_GetClassPtr( BGUI_BASE_GADGET )) {
  233.         /*
  234.         **    Create the class.
  235.         **/
  236.         if ( cl = MakeClass( NULL, NULL, super, sizeof( AOD ), 0L ))
  237.             /*
  238.             **    Setup dispatcher.
  239.             **/
  240.             cl->cl_Dispatcher.h_Entry = ( HOOKFUNC )AreaDispatch;
  241.     }
  242.     return( cl );
  243. }
  244.  
  245. /*
  246. **    Kill the class.
  247. **/
  248. BOOL FreeAreaClass( Class *cl )
  249. {
  250.     return( FreeClass( cl ));
  251. }
  252.